package com.ciaojian.core.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ciaojian.core.model.Roster;
import com.ciaojian.core.model.dto.RosterDTO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 班次 Mapper 接口
 * </p>
 *
 * @author Atlakyn
 * @since 2021-03-25
 */
public interface RosterMapper extends BaseMapper<Roster> {
    /**
     * 查找门店班次
     * 先根据门店id找到门店所属的班次组,再查找班次组下的全部班次
     *
     * @param storeId 门店id
     * @return 班次列表
     */
    @Select("SELECT * " +
            "        FROM d_roster " +
            "        WHERE find_in_set(id, (SELECT rosters " +
            "                               FROM d_roster_group " +
            "                               WHERE find_in_set(#{storeId}, stores)))" +
            "AND status = 1")
    List<Roster> findByStoreId(@Param("storeId") Integer storeId);

    /**
     * 根据 id 查询
     *
     * @param id id
     * @return 数据
     * @see SchedulingMapper#findByExamineId
     */
    @Select("SELECT * FROM d_roster WHERE id = #{id} ")
    RosterDTO getById(@Param("id") Integer id);
}
